package com.zygh.lz.controller.pc;


import com.alibaba.fastjson.JSONObject;
import com.zygh.lz.entity.Template;
import com.zygh.lz.service.TemplateService;
import com.zygh.lz.stapprove.ResultUtil;
import com.zygh.lz.stapprove.SysPcLog;
import com.zygh.lz.vo.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "消息模板")
@RestController
@RequestMapping("/TemplateController")
public class TemplateController {

    @Resource
    private TemplateService templateService;

    @ApiOperation("查询所有记录、、根据创建人查询")
    @GetMapping("list")
    public ResultBean listAll(String creator) {
        return ResultUtil.setOK("success", templateService.listAll(creator));

    }


    @ApiOperation("根据主键查询")
    @GetMapping("getById")
    public ResultBean getById(Integer id) {
        return ResultUtil.setOK("success", templateService.getById(id));
    }

    @ApiOperation("新增，忽略null字段")
    @PostMapping("insert")
    @SysPcLog(module = "新增消息模板",operation = "新增")
    public ResultBean insert(@RequestBody Template template) {
        return ResultUtil.execOp(templateService.insertIgnoreNull(template), "添加");
    }

    @ApiOperation("修改，忽略null字段")
    @PostMapping("update")
    //@SysPcLog(module = "修改消息模板",operation = "修改")
    public ResultBean update(@RequestBody Template template) {
        return ResultUtil.execOp(templateService.updateIgnoreNull(template), "修改");
    }

    @ApiOperation("删除记录")
    @PostMapping("delete")
    //@SysPcLog(module = "删除消息模板",operation = "删除")
    public ResultBean delete(@RequestBody String id) {
        String str = JSONObject.parseObject(id).get("id").toString();
        Integer new_id = Integer.parseInt(str);
        return ResultUtil.execOp(templateService.delete(new_id), "删除");
    }

}
